package org.cocos2d.actions.instant;

import org.cocos2d.actions.CallFuncN;

/**
 * Calls a 'callback' with the node as the first argument N means Node
 */
public class CCCallFuncN extends CCCallFunc {
	
	private CallFuncN callback;
	
	
	public static CCCallFuncN action(Object t, String s) {
		return new CCCallFuncN(t, s, new Class[] { Object.class });
	}
	
	public static CCCallFuncN action(CallFuncN callback) {
		return new CCCallFuncN(callback);
	}
	
	protected CCCallFuncN(){
		
	}
	
	/**
	 * creates the action with the callback
	 * 
	 * @param classes
	 */
	protected CCCallFuncN(Object t, String s, Class<?>[] p) {
		super(t, s, p);
	}
	
	/**
	 * creates the action with the callback
	 * 
	 * @param classes
	 */
	protected CCCallFuncN(CallFuncN callback) {
		super();
		this.callback=callback;
	}
	
	/**
	 * executes the callback
	 */
	public void execute() {
		if (callback != null) {
			callback.execute(target);
		} else {
			try {
				invocation.invoke(targetCallback, new Object[] { target });
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
